package zelix.hack.hacks;

import net.minecraft.client.Minecraft;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import zelix.hack.Hack;
import zelix.hack.HackCategory;
import zelix.utils.ReflectionHelper;
import zelix.utils.Wrapper;
import zelix.value.BooleanValue;
import zelix.value.Mode;
import zelix.value.ModeValue;
import zelix.value.NumberValue;

import java.lang.reflect.Field;

public class FastPlace extends Hack {

    BooleanValue onBlock = new BooleanValue("BlockOnly" , false);
    NumberValue speed = new NumberValue("Speed" , 0D,0D,4D);
    public FastPlace(){
        super("FastPlace" , HackCategory.PLAYER);
        addValue(onBlock,speed);
    }
    @Override
    public void onEnable(){

        super.onEnable();
    }

    @Override
    public void onClientTick(TickEvent.ClientTickEvent event){
        if (onBlock.getValue()){

            if(Wrapper.INSTANCE.player().getHeldItem(EnumHand.MAIN_HAND).getItem() instanceof ItemBlock || Wrapper.INSTANCE.player().getHeldItem(EnumHand.OFF_HAND).getItem() instanceof ItemBlock){
                Field field = ReflectionHelper.findField(Minecraft.class, new String[] { "rightClickDelayTimer", "field_71467_ac" });
                try {

                    if (!field.isAccessible()) {
                        field.setAccessible(true);
                    }

                    field.setInt(Wrapper.INSTANCE.mc(), speed.getValue().intValue());

                } catch (Exception e) {
                    ////////System.out.println(e);
                }
            }
        }else{
            Field field = ReflectionHelper.findField(Minecraft.class, new String[] { "rightClickDelayTimer", "field_71467_ac" });
            try {

                if (!field.isAccessible()) {
                    field.setAccessible(true);
                }

                field.setInt(Wrapper.INSTANCE.mc(), speed.getValue().intValue());

            } catch (Exception e) {
                ////////System.out.println(e);
            }
        }
    }
}
